package com.chenzhen.blog.util;


import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;



/**
 * @author hp
 */
public class FileUtils {

    private FileUtils() {
    }

    public static String getFileAddress(MultipartFile file, String folderName) throws IOException {
        if (file == null || file.getOriginalFilename() == null) {
            return StringUtil.EMPTY;
        }
//        ftp://192.168.1.116/fileservice/demo/images/
        String hostAddress = "47.108.58.155/";
        String fileName = file.getOriginalFilename();
        String fileSuffix = fileName.substring(fileName.lastIndexOf("."));
        fileName = System.currentTimeMillis() + fileSuffix;
        String fileAddress = hostAddress + folderName + "/" + fileName;
        boolean isUpload = FtpUtil.uploadFile("/", folderName + "/", fileName, file.getInputStream());
        return isUpload ? fileAddress : StringUtil.EMPTY;
    }


}